//商品分诶全局组件小仓库
import { defineStore } from "pinia";
import type { CategoryResponseDate } from "@/api/product/attr/type";
import { reqC1, reqC2, reqC3 } from '@/api/product/attr';
import type { CategoryState } from "./type/type";
import { id } from "element-plus/es/locales.mjs";

const useCategoryStore = defineStore('useCategoryStore', {
    state: (): CategoryState => {
        return {
            //一级分类的数组
            c1Arr: [],
            //二级分类的数组
            c2Arr: [],
            //三级分类的数组
            c3Arr: [],
            //存储一节分类的id
            c1Id: '',
            //存储二节分类的id
            c2Id: '',
            //存储三级分类的id
            c3Id: ''
        }
    },
    actions: {
        //获取一级分类
        async getC1() {
            //获取一级数据
            let result: CategoryResponseDate = await reqC1()
            if (result.code == 200) {
                this.c1Arr = result.data
            }

        },
        //获取二级分类
        async getC2() {
            let result = await reqC2(this.c1Id)
            if (result.code == 200) {
                this.c2Arr = result.data
            }

        },
        //获取三级分类
        async getC3() {
            let result = await reqC3(this.c2Id)
            if (result.code == 200) {
                this.c3Arr = result.data
            }
        }
    },
    getters: {

    }
})
export default useCategoryStore;
